package top.moonkit.rs_pro.patterns.login;

import org.springframework.batch.core.annotation.AfterChunk;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import top.moonkit.rs_pro.utils.Mu;

import java.util.List;

/**
 * @author moon
 * @since 0.0.1
 */
@Component
public class LoginProcessorFactory {

    private static List<LoginProcessorService> loginProcessorServices;

    @Autowired
    public void setLoginProcessorService(List<LoginProcessorService> services){
        LoginProcessorFactory.loginProcessorServices = services;
    }


    /**
     * 创建登录处理器
     * @param account 账号
     * @param isPassword 是否是密码
     * @return 处理器
     */
    public static LoginProcessorService buildProcessor(String account, Boolean isPassword) {
        return loginProcessorServices.stream()
                .filter(service -> service.isMe(account, isPassword))
                .findFirst()
                .orElseThrow(() -> new RuntimeException(Mu.m("login.processor_notfound")));
    }


}
